/* GUI CONVERTED from rprsiq04.p (converter v1.75) Fri Sep  1 17:10:44 2000 */
/* rprsiq04.p - PRODUCT LINE RESOURCE LOAD DETAIL INQUIRY               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Report                                        */
/* REVISION: 1.0     LAST MODIFIED: 05/13/86      BY: emb               */
/* REVISION: 4.0     LAST MODIFIED: 12/30/87      BY: wug *A137*        */
/* REVISION: 5.0     LAST MODIFIED: 05/03/89      BY: wug *B098*        */
/* REVISION: 4.0     LAST MODIFIED: 06/20/89      BY: emb *A748*        */
/* REVISION: 4.0     LAST MODIFIED: 02/22/90      BY: wug *D017*        */
/* REVISION: 6.0     LAST MODIFIED: 02/14/91      BY: ram *D351*        */
/* REVISION: 7.0     LAST MODIFIED: 10/11/91      BY: emb *F024*        */
/* REVISION: 7.3     LAST MODIFIED: 10/23/92      BY: ram *G231*        */
/* Revision: 7.3        Last edit: 11/19/92       By: jcd *G339*        */
/* Revision: 7.4        Last edit: 02/24/97       By: *H0QB* Russ Witt  */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 09/01/98   BY: *L08G* A. Shobha    */
/* REVISION: 8.6E     LAST MODIFIED: 09/17/98   BY: *J2Z1* G.Latha      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/08/00   BY: *N0J4* Mudit Mehta      */

         /* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rprsiq04_p_8 "Months Per Col"
/* MaxLen: Comment: */

/*N0J4*------------START COMMENT----------------
 * &SCOPED-DEFINE rprsiq04_p_1 "Workdays      "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_2 "Total Load    "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_3 " LOAD % OF CAPACITY "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_4 "Over/Under    "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_5 "Capacity      "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_6 " F/C Year"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_7 "Past    "
 * /* MaxLen: Comment: */
 *
 * /*J2Z1** &SCOPED-DEFINE rprsiq04_p_9 "Press space bar to display graph" */
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_10 "Prod Line: "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq04_p_11 "Cumulative    "
 * /* MaxLen: Comment: */
 *N0J4*----------END COMMENT----------------- */

/* ********** End Translatable Strings Definitions ********* */


         define variable site like si_site.
         define variable start like pq_start.
         define variable start1 like pq_start.
         define variable rscde like pq_rsc.
         define variable rscde1 like pq_rsc.
         define variable rsdesc like rs_desc format "x(20)".
         define variable interval as integer extent 8.
         define variable sdate like pq_start extent 8.
/*H0QB*  define variable load as decimal extent 8 format ">>>>,>>9".  */
/*H0QB*/ define new shared variable load as decimal extent 8 format ">>>>,>>9"
/*H0QB*/                                 no-undo.
/*H0QB*  define variable cap as decimal extent 8 format ">>>>,>>9".   */
/*H0QB*/ define new shared variable cap as decimal extent 8 format ">>>>,>>9"
/*H0QB*/                                 no-undo.
         define variable ovund as decimal extent 8 format "->>>,>>9".
         define variable cum as decimal extent 8 format "->>>,>>9".
         define variable workdays as integer extent 8 format ">>>>,>>9".
         define variable periods as integer extent 8 format ">>>>,>>9".
         define variable det_load as decimal extent 8 format ">>>>,>>9".
         define variable holiday as integer.
         define variable i as integer.
         define variable j as integer.
         define variable qty like pq_qty.
         define variable wostart as integer.
         define variable nonwdays as decimal.
         define variable elapsedays as integer.
         define variable wdays as integer.
         define variable overlap as integer.
         define variable wointerval as integer.
         define variable offset like pq_lt_off.
         define variable ltoff like pq_lt_off.
         define variable ltoffperiod as integer.
         define variable lead as integer.
         define variable dwm as character format "!(1)" label "D/W/M".
         define variable idays as integer format ">>>>>9"
            label {&rprsiq04_p_8}.
         define variable monthend as integer.
         define variable num_intervals as integer initial 7.
         define variable period as integer.
         define variable prod_start as date.
         define variable prod_end as date.
         define variable more like mfc_logical.

         define new shared variable vq_-ratio as integer extent 7 no-undo.
         define new shared variable vq_-title as character no-undo.
         define new shared variable vq_-period as date extent 14 no-undo.
         define new shared variable vq_-bar-color as character no-undo.
/*H0QB*/ define new shared variable vq_-day-week-month as character no-undo.
         define variable x as integer.



         
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
            site
            rscde
            rsdesc no-attr-space
            start
            idays
         with frame a no-underline width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



         /* SET EXTERNAL LABELS */
         setFrameLabels(frame a:handle).

         site = global_site.
/*L08G*/ {wbrp01.i}

         repeat:
            do:
               if start = ? then start = date(month(today),1,year(today)).
               if dwm = "" then dwm = "M".
               if idays = 0 or idays = ? then idays = 1.
               display site rscde start idays with frame a.
/*L08G*/       if c-application-mode <> 'WEB':U then
               set     site rscde start idays with frame a editing:

                  if frame-field = "site"  then do:

                     /* FIND NEXT/PREVIOUS RECORD */
                     {mfnp.i si_mstr site si_site site si_site si_site}

                     if recno <> ? then do with frame a:
                        site = si_site.
                        display site.
                     end.
                  end.
                  else if frame-field = "rscde"  then do:

                     /* FIND NEXT/PREVIOUS RECORD */
                     {mfnp.i rs_mstr rscde rs_rsc rscde rs_rsc   rs_rsc}

                     if recno <> ? then do with frame a:
/*G231*/                site = rs_site.
                        rscde  = rs_rsc.
/*G231                        display rscde  rs_desc @ rsdesc. */
/*G231*/                display site rscde rs_desc @ rsdesc.
                     end.
                  end.
                  else do:
                     status input.
                     readkey.
                     apply lastkey.
                  end.
               end.

/*L08G*/      {wbrp06.i &command = set
            &fields = "site rscde start idays "
            &frm = "a" }
/*L08G*/      if c-application-mode <> 'WEB':U or
/*L08G*/      (c-application-mode = 'WEB':U and
/*L08G*/       c-web-request begins 'DATA':U) then do:
               rsdesc = "".
               find rs_mstr where rs_rsc = rscde no-lock no-wait no-error.
               if available rs_mstr then do:
                  rscde = rs_rsc.
                  rsdesc = rs_desc.
               end.
               display rscde rsdesc with frame a.

               if day(start) <> 1 then do:
                  start = date(month(start),1,year(start)).
                  display start with frame a.
               end.

               hide frame b.
               hide frame c.
               hide frame d.
/*L08G*/      end.

               /* SELECT PRINTER */
               {mfselprt.i "terminal" 80}
            end.

            /* COMPUTE START DATES */
            sdate[1] = min(today,start).
            {mfcsdate.i}
/*N0J4*     display space(15) {&rprsiq04_p_7} sdate[2 for 6] skip */
/*N0J4*/    display getTermLabelRt("PAST",20) + "    "  format "x(24)"
/*N0J4*/            sdate[2 for 6] skip
            with frame b no-labels STREAM-IO /*GUI*/ .
            display
               space(15) sdate[2] - 1 sdate[3] - 1 sdate[4] - 1 sdate[5] - 1
                         sdate[6] - 1 sdate[7] - 1 sdate[8] - 1 skip
               space(15)
               "-------- -------- -------- -------- -------- -------- -------- "
            with frame b no-labels STREAM-IO /*GUI*/ .

            /* INITIALIZE VARIABLES */
            cap = 0.
            workdays = 0.
            periods = 0.
            load = 0.
            ovund = 0.
            cum = 0.

            /* CALCULATE WORKING DAYS IN EACH INTERVAL */
            {mfcwdays.i site}

/*N0J4*     display {&rprsiq04_p_1} workdays[1 for 7] with frame b no-labels. */
/*N0J4*/    display getTermLabel("WORKDAYS",14)
/*N0J4*/            format "x(14)" workdays[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

            /* CALCULATE CAPACITY IN EACH INTERVAL */
/*G231            {mfccap.i} */
/*G231*/    {mfccap.i site}
/*N0J4*     display {&rprsiq04_p_5} cap[1 for 7] with frame b no-labels. */
/*N0J4*/    display getTermLabel("CAPACITY",14)
/*N0J4*/            format "x(14)" cap[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

            /* CALCULATE LOAD IN EACH PERIOD */
            hide message no-pause.
            if dev = "terminal" then do:
               {mfmsg.i 401 1}
               /* "CALCULATING LOAD" */
            end.
            for each pq_mstr where pq_rsc = rscde
            and pq_site = site
            no-lock with frame c no-labels:
                                
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/
                        /*G339*/

               for each pp_plan where pp_prod_line = pq_prod_line
               and pp_site = pq_site
               and (pp_year >= year(pq_start) or pq_start = ?)
               and (pp_year <= year(pq_end) or pq_end =?)
               no-lock with frame c no-labels width 80:
                                
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/
                        /*G339*/

                  /* CALCULATE LOAD FOR A PRODUCT LINE PRODUCTION PLAN */
                  /* INITIALIZE det_load ARRAY */
                  det_load = 0.

                  period_loop:
                  do period = 1 to 12:

                     /* CALCULATE LOAD FOR A PRODUCT LINE PRODUCTION PLAN */
                     {mfpqld.i}

                  end.

                  /* DISPLAY FORECASTS LOAD DETAIL */
/*N0J4*
 *                display {&rprsiq04_p_6} pp_year det_load[1 for 7] skip
 *                {&rprsiq04_p_10} pq_prod_line.
 *N0J4*/
/*N0J4*/          display " " + getTermLabel("FORECAST_YEAR",8)
/*N0J4*/                  format "x(9)" pp_year det_load[1 for 7] skip
/*N0J4*/          getTermLabel("PRODUCTION_LINE",9) + ": " format "x(11)"
/*N0J4*/          pq_prod_line WITH STREAM-IO /*GUI*/ .

               end.
            end.
            hide frame c.

            /* DISPLAY LOAD OVER/UNDER AND CUMULATIVE */

/*N0J4*     display {&rprsiq04_p_2} load[1 for 7] */
/*N0J4*/    display getTermLabel("TOTAL_LOAD",14) format "x(14)" load[1 for 7]
            with frame d no-labels width 80 STREAM-IO /*GUI*/ .

            do i = 1 to num_intervals + 1:
               ovund[i] = cap[i] - load[i].
               ovund[i] = integer(ovund[i]).
               cum[i] = ovund[i].
               if i > 1 then cum[i] = cum[i] + cum[i - 1].
            end.
/*N0J4*     display {&rprsiq04_p_4} ovund[1 for 7] */
/*N0J4*/    display getTermLabel("OVER/UNDER",14)  format "x(14)" ovund[1 for 7]
            with frame d no-labels width 80 STREAM-IO /*GUI*/ .
/*N0J4*     display {&rprsiq04_p_11} cum[1 for 7] */
/*N0J4*/    display getTermLabel("CUMULATIVE",14) format "x(14)" cum[1 for 7]
            with frame d no-labels width 80 STREAM-IO /*GUI*/ .

            pause 0 no-message.

/*L08G            if path = "terminal" then repeat: */
            if path = "terminal" and
/*L08G*/     c-application-mode <> 'WEB':U then repeat:

/*J2Z1*/       /* HARDCODED MESSAGE HAS BEEN REPLACED */
/*J2Z1**       message {&rprsiq04_p_9}. */
/*J2Z1*/       {mfmsg.i 1143 1}
               readkey.
               if lastkey = 32 then do:

/*H0QB*/          vq_-day-week-month = dwm.
                  do x = 1 to 7:
         /*          load[x] = random(0,200). */
                     vq_-period[x] = sdate[x].
                     vq_-period[x + 7] = sdate[x + 1] - 1.
/*H0QB*              vq_-ratio[x] = load[x] / cap[x] * 100.    */
/*H0QB*/             vq_-ratio[x] = truncate(load[x],0) / truncate(cap[x],0)
/*H0QB*/                            * 100.
                  end.

                  /* ASSIGN THE COLORS */
                  assign vq_-bar-color = if opsys eq "msdos"
                                         and terminal eq "co80"
                                         then "white/red"
                                         else "message".

                  /* ASSIGN THE TITLE */
/*N0J4*           assign vq_-title = {&rprsiq04_p_3}. */
/*N0J4*/          assign vq_-title = " " +
/*N0J4*/            caps(getTermLabel("LOAD_PERCENT_OF_CAPACITY",30)) + " ".
                  /* NOTE LEADING/TRAILING BLANKS */
/*H0QB*/ /*V8+*/
/*H0QB*/      
                     {gprun.i ""gpgraphw.p""}      
               end.
               else leave.
            end.

            {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

            {mfmsg.i 8 1}
         end.
/*L08G*/ {wbrp04.i &frame-spec=a}
